$(document).ready(function() {
	setTimeout("getYzm()", 100);
	//XXX 打开登录页面的时候清除所有内容
	localStorage.clear();
	sessionStorage.clear();
	// 清除所有的cookie
	var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
	if(keys) {
		for(var i = keys.length; i--;) {
			document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString()
		}
	}
});

function getYzm() {
	$("#img").attr("src", ip + "platform/user/getValidateCodeImg.m?t=" + Math.random());
	$("#img").attr("onerror", 'this.src=' + "'" + ip + "platform/user/getValidateCodeImg.m?t=" + Math.random() + "'" + ';this.onerror=null');
}
/**
 * 登录页面的逻辑
 */
var first = true;

function Login() {
	//$(".weui-btn").attr("disabled", false);
	if($("#number").val().trim() == '') {
		$.toast("帐号不能为空!", "text");
		return false;
	}
	if($("#password").val().trim() == '') {
		$.toast("密码不能为空!", "text");
		return false;
	}
	if(/^1(3|4|5|6|7|8|9)\d{9}$/.test($("#number").val().trim())) {
		number = "+86|" + $("#number").val().trim();
	} else {
		$.toptip("手机号码不正确！", 'error');
	}
	var loginReqbody = {
		"type": 0,
		"number": number,
		"password": $("#password").val().trim(),
		"validateCode": ''
	};
	if(first) {
		first = false;
		$.ajax({
			type: "POST",
			url: ip + "platform/user/login.m",
			xhrFields: {
				withCredentials: true
			},
			crossDomain: true,
			data: loginReqbody,
			success: function(data) {
				if(data.statusCode == 0) {
					//$(".weui-btn").attr("disabled", true);
					$.toptip("登录成功！", 'success');
					if(data.result.userName == null) {
						window.location.href = "settingThePaymentPassword.html";
					} else {
						localStorage.setItem('data', JSON.stringify(data));
						window.location.href = "homePage.html";
					}
				} else {
					$.toptip(data.resultDesc, 'error');
					first = true;
				}
			}
		});
	}
}